package com.sugar.queryinfo.module.business.controller.admin.data.dataqueryfyxq;

import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryfyxq.vo.DataQueryFyxqPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryfyxq.vo.DataQueryFyxqRespVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryfyxq.vo.DataQueryFyxqSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.queryinfo.framework.common.pojo.PageParam;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.pojo.CommonResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;
import static com.sugar.queryinfo.framework.common.pojo.CommonResult.success;

import com.sugar.queryinfo.framework.excel.core.util.ExcelUtils;

import com.sugar.queryinfo.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.queryinfo.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.queryinfo.module.business.dal.dataobject.dataqueryfyxq.DataQueryFyxqDO;
import com.sugar.queryinfo.module.business.service.dataqueryfyxq.DataQueryFyxqService;

@Tag(name = "管理后台 - 数据查询-法院详情")
@RestController
@RequestMapping("/business/data-query-fyxq")
@Validated
public class DataQueryFyxqController {

    @Resource
    private DataQueryFyxqService dataQueryFyxqService;

    @PostMapping("/create")
    @Operation(summary = "创建数据查询-法院详情")
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:create')")
    public CommonResult<Long> createDataQueryFyxq(@Valid @RequestBody DataQueryFyxqSaveReqVO createReqVO) {
        return success(dataQueryFyxqService.createDataQueryFyxq(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据查询-法院详情")
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:update')")
    public CommonResult<Boolean> updateDataQueryFyxq(@Valid @RequestBody DataQueryFyxqSaveReqVO updateReqVO) {
        dataQueryFyxqService.updateDataQueryFyxq(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据查询-法院详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:delete')")
    public CommonResult<Boolean> deleteDataQueryFyxq(@RequestParam("id") Long id) {
        dataQueryFyxqService.deleteDataQueryFyxq(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除数据查询-法院详情")
                @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:delete')")
    public CommonResult<Boolean> deleteDataQueryFyxqList(@RequestParam("ids") List<Long> ids) {
        dataQueryFyxqService.deleteDataQueryFyxqListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据查询-法院详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:query')")
    public CommonResult<DataQueryFyxqRespVO> getDataQueryFyxq(@RequestParam("id") Long id) {
        DataQueryFyxqDO dataQueryFyxq = dataQueryFyxqService.getDataQueryFyxq(id);
        return success(BeanUtils.toBean(dataQueryFyxq, DataQueryFyxqRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据查询-法院详情分页")
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:query')")
    public CommonResult<PageResult<DataQueryFyxqRespVO>> getDataQueryFyxqPage(@Valid DataQueryFyxqPageReqVO pageReqVO) {
        PageResult<DataQueryFyxqDO> pageResult = dataQueryFyxqService.getDataQueryFyxqPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataQueryFyxqRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据查询-法院详情 Excel")
    @PreAuthorize("@ss.hasPermission('business:data-query-fyxq:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDataQueryFyxqExcel(@Valid DataQueryFyxqPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DataQueryFyxqDO> list = dataQueryFyxqService.getDataQueryFyxqPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数据查询-法院详情.xls", "数据", DataQueryFyxqRespVO.class,
                        BeanUtils.toBean(list, DataQueryFyxqRespVO.class));
    }

}